const screenWidth = window.innerWidth
const screenHeight = window.innerHeight

import Sprite from './sprite'
import global from './global'


/**
 * 子弹
 */
export default class Bullet extends Sprite{

  constructor() {
    super('images/bullet.png', 16, 30)
    this.top = 0
    this.speed = 0
  }
  
  init(x, y , speed = 10){
    this.x = x
    this.y = y
    this.speed = speed
    this.visible = true
  }

  update() {
    this.y = this.y - this.speed
    if (this.y < 0) {
      this.visible = false
      global.removeBullet(this)
    }
  }

  render(ctx) {
    if (!this.visible){
      return
    }
    ctx.drawImage(
      this.img, this.x, this.y, this.width, this.height
    )
  }
}
